<?php
/**
 * Created by PhpStorm.
 * User: Cloud
 * Date: 2018/4/14
 * Time: 14:37
 */
?>
<!DOCTYPE html>
<html>
<head>
    <!--[if lt IE 7]>
    <div class="ie6_error">还在用<strong>漏洞百出的IE6浏览器</strong>么？为了您的网络安全，请升级浏览器 <a target="_blank"
                                                                               href="http://browsehappy.com">立即升级</a>
    </div>
    <![endif]-->

    <meta charset="utf-8">
    <title>审批中心-消息通知-文具1号</title>
    <meta name="description"
          content="文具1号作为上海办公用品供货商公司,专为世界500强企业及SOHO办公族提供网上商城一站式办公耗材批发及采购服务,一站式选购办公日用文具用品,厂家直销,好货又便宜【阳光采购就上文具1号 阳光价格 老板放心 品质保障 员工省力】"/>
    <meta name="keywords" content="办公用品,办公文具,办公文具网站,文具网站,办公用品网,文具采购网,金万年"/>
    <meta name="copyright" content="上海易推信息科技有限公司"/>
    <meta name="renderer" content="webkit">
    <link rel="shortcut icon" href="favicon.ico"/>
    <base href="<?php echo base_url(); ?>"/>
    <link rel="stylesheet" href="public/js/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="public/css/base.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/cost-center.css"/>
    <link href="public/css/yuan.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="public/css/list_bought.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/order-manage.css"/>
    <!--[if lte IE 9]>
    <script type="text/javascript" src="public/js/html5shiv-printshiv-3.js"></script>
    <![endif]-->


    <div class="bg">
        <?php $this->load->view('common/header.php'); ?>
        <div class="container mt30">
            <div class="my-center-container">
                <div class="my-center-sidebar">
                    <?php
                    //                $shop_user_id=2;
                    if (isset($this->session->customer_id)) {
                        $shop_user_id = $_SESSION['customer_info']['shop_user_id'];
                        $sql = 'select identity,id from app_customer WHERE  id = ' . $this->session->customer_id;
                        $identitys = $this->db->query($sql)->row_array();
                        if ($identitys['identity'] == 1) {
                            $sql = "select is_account,account_period_type from app_admin WHERE customer_id = " . $this->session->customer_id;
                            $admin_info = $this->db->query($sql)->row_array();
                            if ($admin_info['is_account'] == 1) {
                                if ($admin_info['account_period_type'] == 2) {
                                    $bills = $this->db->where('customer_id', $identitys['id'])->where('status', 0)->from('app_bill ')->get()->result_array();
                                    $bills = count($bills);
                                } else {
                                    $bills = $this->db->where('customer_id', $identitys['id'])->where(array('status' => 0, 'bill_date != ' => NULL))->from('app_bill ')->join('app_bill_month', 'app_bill_month.bill_id = app_bill.id')->get()->result_array();
                                    $bills = count($bills);
                                }
                            }
                        }
                        $customer_id = $identitys['id'];
                        $news = $this->db->where('receiver_customer_id', $identitys['id'])->where('read_status', 0)->from('message_history')->get()->result_array();

//获取admin下面的子辈和孙辈的(包含自己)
//                        $member = $this->db->from('app_customer')->select("id")->where('parent_id', $customer_id)->get()->result_array();
//                        $str[] = $customer_id;
//                        foreach ($member as $k => $v) {
//                            $str[] = $v['id'];
//                        }
//                        foreach ($member as $k => $v) {
//                            $where = array('parent_id' => $v['id']);
//                            $row = $this->db->from('app_customer')->select("id")->where($where)->get()->result_array();
//                            foreach ($row as $key => $val) {
//                                $str[] = $val['id'];
//                            }
//                        }
                        $member = $this->db->from('app_customer')->select("id")->where('parent_id', $customer_id)->get()->result_array();
                        $str[] = $customer_id;
                        foreach ($member as $k => $v) {
                            $str[] = $v['id'];
                        }
                        foreach ($member as $k => $v) {
                            $where = array('parent_id' => $v['id']);
                            $row = $this->db->from('app_customer')->select("id")->where($where)->get()->result_array();
                            foreach ($row as $key => $val) {
                                $str[] = $val['id'];
                            }
                        }
                        foreach ($str as $key => $value) {
                            if($value == $customer_id){
                                unset($str[$key]);
                            }
                        }
                        if(count($str) == ""){
                            $str[] = "-1";
                        }
                        $count1 = $this->db->where_in('customer_id', $str)->where('status', 2)->from('app_temp')->count_all_results();
                        $count2 = $this->db->where_in('customer_id', $str)->where('status', 4)->from('app_temp')->count_all_results();
                        $count = $count1 + $count2;
                        $newspulls = count($news);
                    }
                    ?>
                    <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="demo">
                        <li class="layui-nav-item  "><a
                                    href="<?php echo base_url('approve/index?id=2'); ?>">审批中心（<?php echo $count; ?>）</a>
                        </li>
                        <?php if (isset($admin_info)): ?>
                            <?php if ($identitys['identity'] == 1 && $admin_info['is_account'] == 1): ?>
                                <li class="layui-nav-item "><a
                                            href="<?php echo base_url('news/news_bill'); ?>">账期提醒（<?php echo $bills; ?>
                                        ）</a></li>
                            <?php endif; ?>
                        <?php endif; ?>
                        <li class="layui-nav-item layui-nav-itemed"><a style="border-bottom:0;"
                                                                       href="<?php echo base_url('news/news_pull'); ?>">消息通知<em>（<?php echo $newspulls; ?>
                                    ）</em></a></li>
                    </ul>
                </div>
                <div class="my-center-right" style="overflow:visible; border: none;background-color: #f9f9f9">

                    <div class="my-center-right-cont" style="padding: 0;">
                        <div class="order-manage-cont" style="margin-top:0; width:992px; padding: 0">
                            <div id="main-content">

                                <div class="bought-list">
                                    <p class="bought-list-tit">
                                        交易提醒
                                    </p>
                                    <form class="skin-gray clearfix bought-search" action="" method="post"
                                          style="padding-bottom:0;">

                                        <div class="remide-box" gdata-spm="7" style="padding:5px 0">
                                            <ul>
                                                <li><a href="<?php echo base_url(); ?>news/news_pull/?statu=1"
                                                       class="checkbox-icon   <?php if ($status == 1): ?> select  <?php endif ?>"
                                                       id="1">已读</a></li>
                                                <li><a href="<?php echo base_url(); ?>news/news_pull/?statu=0"
                                                       class="checkbox-icon <?php if ($status == 0): ?> select  <?php endif ?>"
                                                       id="0">未读</a></li>
                                            </ul>

                                            <?php if (count($newspull) > 0): ?>
                                                <?php if ($status == 1): ?>
                                                    <button class=" ajax-oper J_MakePoint button search-btn "
                                                            style="float:left; letter-spacing: 0; width:110px;text-align: center"
                                                            value="4" name="status" type="button"
                                                            href="<?php echo base_url('news/news_pull'); ?>/?restatus=1&statu=<?php echo $status; ?>">
                                                        删除全部已读消息
                                                    </button>
                                                <?php endif ?>
                                                <?php if ($status == 0): ?>
                                                    <button class="ajax-oper J_MakePoint button search-btn "
                                                            style="float:left; letter-spacing: 0; width:110px;text-align: center"
                                                            value="4" name="status" type="button"
                                                            href="<?php echo base_url('news/news_pull'); ?>/?restatus=0&statu=<?php echo $status; ?>">
                                                        删除全部未读消息
                                                    </button>

                                                    <button class=" ajax-oper J_MakePoint button search-btn "
                                                            style="float:left; letter-spacing: 0; width:110px;text-align: center"
                                                            value="3" name="status" type="button"
                                                            href="<?php echo base_url('news/news_pull'); ?>/?read_status=1&p=<?php echo $nowPage; ?>&statu=<?php echo $status; ?>">
                                                        全部设为已读
                                                    </button>
                                                <?php endif ?>
                                            <?php endif; ?>
                                            <!--                                            <button class="J_MakePoint button search-btn" type="button" value="4">-->
                                            <!--                                                <a href="-->
                                            <? //= $nexturl ?><!--">下一页</a>-->
                                            <!--                                            </button>-->
                                        </div>
                                    </form>
                                    <div class="corporate-invoice-table-box w100 bg-fff">
                                        <table border="1" class="corporate-invoice-tab corporate-invoice-sp">
                                            <thead>
                                            <tr>
                                                <!--                      <th width="120"> <span class="checkbox-icon checkbox-icon-msg"></span>发件人</th>-->
                                                <th width="120">发件人</th>
                                                <th width="300">内容</th>
                                                <th width="150">发送时间</th>
                                                <th width="230">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>

                                            <?php if (count($newspull)): ?>
                                                <?php foreach ($newspull as $news): ?>
                                                    <tr>
                                                        <td><?php echo $news['name'] ?></td>
                                                        <td class="tac"
                                                            title="<?php echo $news['content'] ?>"><?php echo $news['content'] ?></td>
                                                        <td class=""><?php echo $news['created_at'] ?></td>
                                                        <td class="corporate-invoice-tab-time td02 <?php if ($status == 1): ?>readed<?php endif; ?>"
                                                            style="text-align: center;">
                                                            <a href="javascript:void(0)" style="width: 24%"
                                                               class="corporate-invoice-tab-msg-active corporate-invoice-tab-msg-active-red color-blue"
                                                               onclick="$.get('news/readed/?id=<?php echo $news['id'] ?>');layer.alert('<?php echo trim($news['content']) ?>')">查看</a>
                                                            <?php if (in_array($news['title'], array('单品额度和预算申请', '单品额度申请', '可用预算申请'))): ?>
                                                                <a href="<?php echo base_url() ?>cost_center/manager_user_edit?id=<?php echo $news['send_customer_id'] ?>#set-budget"
                                                                   style="width: 24%"
                                                                   class="corporate-invoice-tab-msg-active corporate-invoice-tab-msg-active-red color-blue adjust_the_budget">调整预算</a>
                                                            <?php endif; ?>
                                                            <?php if (in_array($news['title'], array('账期即将到期', '账期已到期')) && $news['key']): ?>
                                                                <a href="<?php echo base_url('pay/index'); ?>?bn=<?php echo $news['key']; ?>"
                                                                   style="width: 24%"
                                                                   class="corporate-invoice-tab-msg-active corporate-invoice-tab-msg-active-red color-blue">账期还款</a>
                                                            <?php endif; ?>
                                                            <a href="news/news_pull/?del=<?php echo $news['id'] ?>&p=<?php echo $nowPage; ?>&statu=<?php echo $status; ?>"
                                                               style="width: 24%"
                                                               class=" ajax-oper corporate-invoice-tab-msg-active corporate-invoice-tab-msg-active-red color-blue">删除</a>
                                                            <?php if ($news['read_status'] == 0) : ?>
                                                                <a href="<?= base_url() ?>news/news_pull?status=0&id=<?= $news['id'] ?>&p=<?= $nowPage; ?>&statu=<?= $status; ?>"
                                                                   style="width: 24%"
                                                                   class="ajax-oper  corporate-invoice-tab-msg-active color-blue">标为已读</a>
                                                            <?php elseif ($news['read_status'] == 1): ?>
                                                            <?php endif; ?>
                                                        </td>
                                                    </tr>
                                                <?php endforeach; ?>
                                            <?php endif; ?>
                                            </tbody>
                                        </table>

                                        <div class="corporate-invoice-page-box">
                                            <?php if ($total_page > 1): ?>
                                                <?php if ($nowPage > 1): ?>
                                                    <a href="<?= $preurl ?>" class="page-prev">上一页</a>
                                                <?php endif; ?>
                                                <?php if ($nowPage != $total_page): ?>
                                                    <a href="<?= $nexturl ?>" class="page-next">下一页</a>
                                                <?php endif; ?>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                                <!--end bought-list-->
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <?php $this->load->view('common/bottom.php'); ?>
    <script type="text/javascript" src="public/js/jquery.min.js"></script>
    <script src="public/js/layui/layui.js"></script>
    <script type="text/javascript" src="public/js/index.js"></script>
    <script type="text/javascript" src="public/js/owl.carousel.min.js"></script>

    <script>
        layui.use(['element', 'form', 'layedit', 'laydate', 'upload'], function () {
            var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;
            var $ = layui.jquery
                , upload = layui.upload;

//监听导航点击
            element.on('nav(demo)', function (elem) {
//console.log(elem)
//      layer.msg(elem.text());
            });
//日期
            laydate.render({
                elem: '#date-star'
            });
            laydate.render({
                elem: '#date-end'
            });
            laydate.render({
                elem: '#date'
            });
//监听提交
            form.on('submit(demo1)', function (data) {
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                });
                return false;
            });


        });
    </script>
    <script>
        $(function () {
            $(".checkbox-icon").click(function () {
                $(this).toggleClass('select');
                $(this).parent().siblings().find('.checkbox-icon').removeClass('select');
            });

            $(".adjust_the_budget").click(function () {

            })

            $('body').on('click', '.ajax-oper', function (e) {
                $.get($(this).attr('href'), function (result) {
                    layer.msg(result);
                    setTimeout(function () {
                        location.reload();
                    }, 1000)
                })
                e.stopPropagation();
                return false;
            });
        });


    </script>

